package cn.rongdao.jrkabao.ui.areapicker;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.mifengkong.frtools.ui.activity.FRStartActivity;

import butterknife.BindView;
import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.base.BaseAutoFinishActivity;


public class AreaPickerActivity extends BaseAutoFinishActivity implements View.OnClickListener {

    @BindView(R.id.citypicker)
    CityPicker cityPicker;
    @BindView(R.id.activity_area_picker_cancel)
    TextView cancel;
    @BindView(R.id.activity_area_picker_finish)
    TextView finish;

    private int position;

    public static void start(Activity activity, int position) {
        Bundle bundle = new Bundle();
        bundle.putInt("position", position);
        FRStartActivity.startForResult(activity, AreaPickerActivity.class, bundle, 2);
    }

    @Override
    protected int layoutRes() {
        return R.layout.activity_area_picker;
    }

    @Override
    protected void initView() {
        super.initView();
        cancel.setOnClickListener(this);
        finish.setOnClickListener(this);
        initData();
    }

    private void initData() {
        try {
            position = getIntent().getIntExtra("position", 0);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.activity_area_picker_cancel:
                finish();
                overridePendingTransition(0, R.anim.activity_up2down);
                break;
            case R.id.activity_area_picker_finish:
                Intent intent = new Intent();
                intent.putExtra("position", position);
                intent.putExtra("adress", cityPicker.getCity_string());
                setResult(RESULT_OK, intent);
                finish();
                overridePendingTransition(0, R.anim.activity_up2down);
                break;
        }
    }
}